/**
 * 
 */
package com.scaffold.upload;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;

import wangjg.commons.io.FileIOHelper;
import wangjg.commons.io.FilePathHelper;

/**
 * @author wangjg
 *
 */
public class UploadHandle {
	private String url;
	
	public String confirm(Map<String,String> upParams) {
		HttpURLConnection conn = null;
		try {
			String path = upParams.get("path");
			String destPath = upParams.get("destDir")+'/'+FilePathHelper.getFileName(path);
			URL _url = new URL(url + "?path=" + path + "&destPath="+destPath);
			conn = (HttpURLConnection) _url.openConnection();
			InputStream in = (InputStream) conn.getContent();
			String newPath = FileIOHelper.StreamToString(in, "utf-8");
			return newPath;
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			if(conn!=null){
				conn.disconnect();
			}
		}
		return null;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}
	
}
